package com.im.service.group.controller;

import com.im.common.model.RestResponse;
import com.im.service.group.model.req.*;
import com.im.service.group.model.resp.AddMemberResp;
import com.im.service.group.service.ImGroupMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/v1/group/member")
@Api(tags = "群组成员控制器")
public class ImGroupMemberController {

    @Autowired
    ImGroupMemberService groupMemberService;

    @PostMapping("/importGroupMember")
    @ApiOperation("导入群组成员")
    public RestResponse<List<AddMemberResp>> importGroupMember(@RequestBody @Validated ImportGroupMemberReq req, @RequestParam Integer appId, @RequestParam String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        List<AddMemberResp> addMemberResps = groupMemberService.importGroupMember(req);
        return RestResponse.success(addMemberResps);
    }

    @PostMapping("/add")
    @ApiOperation("添加群组成员")
    public RestResponse<List<AddMemberResp>> addMember(@RequestBody @Validated AddGroupMemberReq req, @RequestParam Integer appId, @RequestParam String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        List<AddMemberResp> memberResps = groupMemberService.addMember(req);
        return RestResponse.success(memberResps);
    }

    @PostMapping("/remove")
    @ApiOperation("移除群组成员")
    public RestResponse removeMember(@RequestBody @Validated RemoveGroupMemberReq req, @RequestParam Integer appId, @RequestParam String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        groupMemberService.removeMember(req);
        return RestResponse.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新群组成员信息")
    public RestResponse updateGroupMember(@RequestBody @Validated UpdateGroupMemberReq req, @RequestParam Integer appId, @RequestParam String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        groupMemberService.updateGroupMember(req);
        return RestResponse.success();
    }

    @PostMapping("/speak")
    @ApiOperation("群组成员发言")
    public RestResponse speak(@RequestBody @Validated SpeaMemberReq req, @RequestParam Integer appId, @RequestParam String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        groupMemberService.speak(req);
        return RestResponse.success();
    }

}

